package com.naico.core.pojo;

import com.naico.util.TableFormatter;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * User: Dawood Ajaz
 * Date: Dec 27, 2008
 * Time: 10:12:53 PM
 */
public class PaymentSchedule implements Serializable {
    private static final long serialVersionUID = 1L;
    private List<PaymentScheduleItem> paymentScheduleItems;

    public List<PaymentScheduleItem> getPaymentScheduleItems() {
        return paymentScheduleItems;
    }

    public void setPaymentScheduleItems(List<PaymentScheduleItem> paymentScheduleItems) {
        this.paymentScheduleItems = paymentScheduleItems;
    }

    /**
     * this payment schedule's creditor name which is the first item's creditor's name
     *
     * @return returns this payment schedule's creditor name
     */
    public String getCreditorName() {
        String retVal = "";
        if (paymentScheduleItems != null && paymentScheduleItems.size() > 0)
            retVal = paymentScheduleItems.get(0).getCreditorName();
        return retVal;
    }

    public String toString() {
        TableFormatter table = new TableFormatter();
        DateFormat dateFormat = new SimpleDateFormat("MM-yyyy");
        NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();

        table.addColumn("Month", 10, dateFormat, true);
        table.addColumn("BeginningBalance", 16, currencyFormat, true);
        table.addColumn("Interest", 10, currencyFormat, true);
        table.addColumn("Payment", 14, currencyFormat, true);
        table.addColumn("EndingBalance", 16, currencyFormat, true);
        table.addColumn("Roll-over", 10, true);

        for (int i = 0; i < this.getPaymentScheduleItems().size(); i++) {
            PaymentScheduleItem item = this.getPaymentScheduleItems().get(i);
            table.setData(i, 0, item.getMonth());
            table.setData(i, 1, item.getBeginningBalance());
            table.setData(i, 2, item.getInterest());
            table.setData(i, 3, item.getPayment());
            table.setData(i, 4, item.getEndingBalance());
            table.setData(i, 5, (item.isRollOver()) ? "Yes" : "No");
        }

        return table.toString();
    }
}
